package com.zhongkai.controller;

import com.zhongkai.app.service.AirUserService;
import com.zhongkai.model.utils.ZhongkaiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 系统账号管理
 */
@Controller
public class AIRUserController {


    @Autowired
    private AirUserService airUserService;


    /**
     * 账号添加
     *
     * @param user_name 账户名
     * @param pass_word 密码
     * @param set_name  姓名
     * @param set_sex   性别
     * @param set_phone 111.61.64.62号
     * @param set_role  角色id
     */
    @RequestMapping(value = "/air_user/add", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addAIR(
            String user_name, //手机号码
            String pass_word,//密码
            String set_name, //姓名
            String set_sex,         //用户性别
            String set_phone,         //手机号
            @RequestParam(defaultValue = "0") Integer set_role         //角色
/*            , String uProvince //省
            , String uCity //市
            , String uCountry //区
            , String uTown //乡镇*/

    ) {


/*        System.out.println(
                 phone+ //手机号码
                 password+//密码
                 name +//姓名
                 address+         //详细地址
                 uProvince+ //省
                 uCity+ //市
                 uCountry+ //区
                 uTown //乡镇
        );*/

        ZhongkaiResult zhongkaiResult = airUserService.addAIR(
                user_name
                , pass_word
                , set_name
                , set_sex
                , set_phone
                , set_role

        );

        return zhongkaiResult;
    }


    /**
     * 账号修改
     *
     * @param uuid      账户uuid
     * @param pass_word 密码
     * @param set_name  姓名
     * @param set_sex   性别
     * @param set_phone 手机号
     * @param set_role  角色id
     */
    @RequestMapping(value = "/air_user/update", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult updateAIR(
            String uuid, String pass_word, String set_name, String set_sex, String set_phone, @RequestParam(defaultValue = "0") Integer set_role
/*            , String uProvince //省
            , String uCity //市
            , String uCountry //区
            , String uTown //乡镇*/

    ) {


/*        System.out.println(
                 phone+ //手机号码
                 password+//密码
                 name +//姓名
                 address+         //详细地址
                 uProvince+ //省
                 uCity+ //市
                 uCountry+ //区
                 uTown //乡镇
        );*/

        ZhongkaiResult zhongkaiResult = airUserService.updateAIR(
                uuid
                , pass_word
                , set_name
                , set_sex
                , set_phone
                , set_role

        );

        return zhongkaiResult;
    }




    /**
     * 账号删除
     *
     * @param uuid 账户uuid
     */
    @RequestMapping(value = "/air_user/remove", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult removeAIR(
            String uuid

    ) {


/*        System.out.println(
                 phone+ //手机号码
                 password+//密码
                 name +//姓名
                 address+         //详细地址
                 uProvince+ //省
                 uCity+ //市
                 uCountry+ //区
                 uTown //乡镇
        );*/

        ZhongkaiResult zhongkaiResult = airUserService.removeAIR(
                uuid

        );

        return zhongkaiResult;
    }


    /**
     * 账号列表
     *
     * @param page  页码
     * @param rows 条数
     */
    @RequestMapping(value = "/air_user/air_list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult listAIR(
            @RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer rows

    ) {


/*        System.out.println(
                 phone+ //手机号码
                 password+//密码
                 name +//姓名
                 address+         //详细地址
                 uProvince+ //省
                 uCity+ //市
                 uCountry+ //区
                 uTown //乡镇
        );*/

        ZhongkaiResult zhongkaiResult = null;
        try {
            zhongkaiResult = airUserService.listAIR(
                    page,rows

            );
        } catch (Exception e) {
            e.printStackTrace();

            return ZhongkaiResult.build(401, "查询失败");
        }

        return zhongkaiResult;
    }


    /**
     * 角色列表
     */
    @RequestMapping(value = "/air_user/set_list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult listAIR_Set(


    ) {


/*        System.out.println(
                 phone+ //手机号码
                 password+//密码
                 name +//姓名
                 address+         //详细地址
                 uProvince+ //省
                 uCity+ //市
                 uCountry+ //区
                 uTown //乡镇
        );*/

        ZhongkaiResult zhongkaiResult = airUserService.listAIR_Set();

        return zhongkaiResult;
    }

}
